package com.cloud.bc.controller.ajax.center;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.bc.model.domain.UserInfo;
import com.cloud.bc.model.entity.BcFinanceRecords;
import com.cloud.bc.model.entity.BcGifts;
import com.cloud.bc.model.request.LikeRequest;
import com.cloud.bc.model.request.PhotoReq;
import com.cloud.bc.model.response.AjaxResp;
import com.cloud.bc.service.BcFinanceRecordsService;
import com.cloud.bc.service.BcUsersService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@AllArgsConstructor
@RestController
@RequestMapping("m/ajax/financerecords")
public class Ajax_FinanceRecordsController {

    private final BcFinanceRecordsService bcFinanceRecordsService;
    private final BcUsersService bcUsersService;

    @GetMapping("list")
    public AjaxResp list(HttpServletRequest request,
                         HttpServletResponse response,
                         LikeRequest req
    ) {
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        Page page = new Page();
        page.setCurrent(Convert.toInt(req.getPage(), 1));
        AjaxResp ajaxResp = new AjaxResp();
        BcFinanceRecords bcFinanceRecords = new BcFinanceRecords();
        bcFinanceRecords.setUserId(userInfo.getId());
        //货币类型
        bcFinanceRecords.setCurrencyType(req.getType());
        IPage<BcFinanceRecords> bcFinanceRecordsIPage = bcFinanceRecordsService.selectPage(page, bcFinanceRecords);
        ajaxResp.setList(bcFinanceRecordsIPage.getRecords());
        return ajaxResp;
    }
}
